package com.sx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sx.dao.PromotionAdMapper;
import com.sx.domain.PromotionAd;
import com.sx.domain.PromotionAdVo;
import com.sx.service.PromotionAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.print.Pageable;
import java.util.Date;
import java.util.List;

@Service
public class PromotionAdServiceImpl implements PromotionAdService {
    @Autowired
    private PromotionAdMapper promotionAdMapper;


    //PageInfo是mybatis里面分页查询的一个功能，分装分页数据
    @Override
    public PageInfo<PromotionAd> findPromotionAdByPage(PromotionAdVo promotionAdVo) {
        PageHelper.startPage(promotionAdVo.getCurrentPage(),promotionAdVo.getPageSize());
        List<PromotionAd> promotionAdByPage = promotionAdMapper.findPromotionAdByPage();
        PageInfo<PromotionAd> promotionAdPageInfo = new PageInfo<>(promotionAdByPage);
        return promotionAdPageInfo;
    }



    //广告上线和下线
    @Override
    public void updatePromotionAdStatus(int id, int status) {
            //封装数据
        Date date = new Date();
        PromotionAd promotionAd = new PromotionAd();
        promotionAd.setId(id);
        promotionAd.setStatus(status);
        promotionAd.setUpdateTime(date);
        promotionAdMapper.updatePromotionAdStatus(promotionAd);
    }

    @Override
    public void savePromotionAd(PromotionAd promotionAd) {
        promotionAdMapper.savePromotionAd(promotionAd);
    }

    @Override
    public void updatePromotionAd(PromotionAd promotionAd) {
        promotionAdMapper.updatePromotionAd(promotionAd);
    }

    @Override
    public PromotionAd updatePromotionAdById(Integer id) {
        PromotionAd promotionAd = promotionAdMapper.updatePromotionAdById(id);
        return promotionAd;

    }


}
